package com.ruoyi.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.article.domain.ArticleDetail;
import com.ruoyi.article.service.IArticleDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章详情 Controller
 * 
 * @author rey
 * @date 2022-02-04
 */
@RestController
@RequestMapping("/article/detail")
public class ArticleDetailController extends BaseController
{
    @Autowired
    private IArticleDetailService articleDetailService;

    /**
     * 查询文章详情 列表
     */
    @PreAuthorize("@ss.hasPermi('article:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleDetail articleDetail)
    {
        startPage();
        List<ArticleDetail> list = articleDetailService.selectArticleDetailList(articleDetail);
        return getDataTable(list);
    }

    /**
     * 导出文章详情 列表
     */
    @PreAuthorize("@ss.hasPermi('article:detail:export')")
    @Log(title = "文章详情 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleDetail articleDetail)
    {
        List<ArticleDetail> list = articleDetailService.selectArticleDetailList(articleDetail);
        ExcelUtil<ArticleDetail> util = new ExcelUtil<ArticleDetail>(ArticleDetail.class);
        util.exportExcel(response, list, "文章详情 数据");
    }

    /**
     * 获取文章详情 详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:detail:query')")
    @GetMapping(value = "/{articleDetailId}")
    public AjaxResult getInfo(@PathVariable("articleDetailId") Long articleDetailId)
    {
        return AjaxResult.success(articleDetailService.selectArticleDetailByArticleDetailId(articleDetailId));
    }

    /**
     * 新增文章详情 
     */
    @PreAuthorize("@ss.hasPermi('article:detail:add')")
    @Log(title = "文章详情 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleDetail articleDetail)
    {
        return toAjax(articleDetailService.insertArticleDetail(articleDetail));
    }

    /**
     * 修改文章详情 
     */
    @PreAuthorize("@ss.hasPermi('article:detail:edit')")
    @Log(title = "文章详情 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleDetail articleDetail)
    {
        return toAjax(articleDetailService.updateArticleDetail(articleDetail));
    }

    /**
     * 删除文章详情 
     */
    @PreAuthorize("@ss.hasPermi('article:detail:remove')")
    @Log(title = "文章详情 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleDetailIds}")
    public AjaxResult remove(@PathVariable Long[] articleDetailIds)
    {
        return toAjax(articleDetailService.deleteArticleDetailByArticleDetailIds(articleDetailIds));
    }
}
